package com.competition.reception.controller;


import com.competition.commonutils.R;
import com.competition.reception.entity.Manage;
import com.competition.reception.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * <p>
 * 管理员登录表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-04-03
 */
@RestController
@RequestMapping("/reception/manage")
@CrossOrigin
@Api(description = "管理员操作的相关接口")
public class ManageController {

    @Resource
    private ManageService manageService;
    //添加管理员
    @PostMapping("addManage")
    @ApiOperation("添加管理员")
    public R addManage(@RequestBody Manage manage){
        manageService.addManage(manage);
        return R.ok();
    }

    @ApiOperation("编辑管理员")
    @PostMapping("updateManage")
    public R updateManage(@RequestBody Manage manage){
        manageService.updateManage(manage);
        return R.ok();
    }

    /**
     *
     * @param page 页数
     * @param limit 每页数据
     * @Param manageUsername 管理员用户名
     * @return
     */
    @ApiOperation("根据条件查询所有管理员,查询条件key,当前页以及每页多少条数据")
    @GetMapping("selectManage/{page}/{limit}")
    public R selectManage(@PathVariable("page") Integer page,
                               @PathVariable("limit") Integer limit,
                               @RequestParam(required = false) String condition
    ){
        return manageService.selectManage(page,limit,condition);
    }
    @ApiOperation("根据id删除管理员")
    @PostMapping("deleteManage/{id}")
    public R deleteManage(@PathVariable("id") String id){
        manageService.removeManage(id);
        return R.ok();
    }
    @ApiOperation("根据id将管理员添加至黑名单或者取消黑名单")
    @PostMapping("BlacklistManage/{id}")
    public R BlacklistManage(@PathVariable("id") String id){
        Integer is_balck=manageService.BlacklistManage(id);
        return R.ok().data("is_balck",is_balck);
    }

    @ApiOperation("根据id查询出管理员的相关信息，用于做修改时管理员数据的回显")
    @GetMapping("getManageUpdateInfo/{id}")
    public R getManageUpdateInfo(@PathVariable String id){
        Manage manage = manageService.getById(id);
        return R.ok().data("manage",manage);
    }

}

